<?php
class tab extends CI_Controls{

	public $headers;
	public $contents;


	function __construct(){
		parent::__construct();
		$this->headers=array();
		$this->contents=array();
	}

	function drawContent(){
		if(!empty($this->headers) && !empty($this->contents)){
			//div principal

			$tabConten=new div();
			$tabConten->atributos=$this->atributos;
			//ul para las cabeceras
			$lista=new ul();

			$nheaders=count($this->headers);
			for($i=0;$i<$nheaders;++$i){
				$li=new li();
				/*$link=new anchor();
				 $link->att('href','#');
				$link->value=$this->headers[$i];*/
				$link="<a href=#".$this->att('id')."-".($i+1).">".$this->headers[$i]."</a>";
				$li->value.=$link;
				$lista->value.=$li;
			}
			$tabConten->addControl($lista);
				
			$ncontents=count($this->contents);
			for($i=0;$i<$ncontents;++$i){
				$cont=new div();
				$cont->att('id',$this->att('id').'-'.($i+1));
				$cont->value=$this->contents[$i];
				$tabConten->addControl($cont);
			}
			$this->tabScript();
			return $tabConten ;
		}
	}

	private function tabScript(){

		ob_start();
		?>
			<script>
			 $(function() {
			        $( "#<?php echo $this->att('id')?>" ).tabs();
			    });
			</script>
		<?php
			
		 $this->CI->dynamic_assets->add_code_js(ob_get_clean());
			
	}
}